<?php
/**
 * 
 * Enter description here ...
 * @author Aaron
 *
 */
class Ddup_Reviews_Model_Review extends Mage_Core_Model_Abstract
{
	const APPROVED_REVIEWS_DEFAULT_COUNT = 3;
	/**
	 * 
	 * Approved Reviews
	 */
	public function approved ()
	{
		$model = Mage::getModel('review/review');
        $collection = $model->getProductCollection();
        $collection->addStatusFilter(Mage_Review_Model_Review::STATUS_NOT_APPROVED)
        		->addOrder(new Zend_Db_Expr('RAND()'))
        		->setPageSize(self::APPROVED_REVIEWS_DEFAULT_COUNT);
        foreach ($collection as $product) {
        	$review = Mage::getModel('review/review')->load($product->getReviewId());
			$review->setStatusId(Mage_Review_Model_Review::STATUS_APPROVED)
				->setCreatedAt($this->_getRandomTime())
				->save()
				->aggregate();
        }
	}
	
	/**
	 * 
	 * Random 24 Hours
	 */
	private function _getRandomTime()
	{
		$startTime = time()-24*3600*7;
		$endTime = time();
		$randomTime = mt_rand($startTime, $endTime);
		
		return date('Y-m-d H:i:s', $randomTime);
	}
}